package com.hziee.graduate.ticket.dao;

import java.util.List;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.hziee.graduate.ticket.vo.AreaVO;
import org.apache.ibatis.annotations.Param;
import com.hziee.graduate.ticket.entity.Region;
import org.apache.ibatis.annotations.Select;


public interface RegionDao extends BaseMapper<Region> {

    /**
     * 批量新增数据（MyBatis原生foreach方法）
     *
     * @param entities List<Region> 实例对象列表
     * @return 影响行数
     */
    int insertBatch(@Param("entities") List<Region> entities);

    /**
     * 批量新增或按主键更新数据（MyBatis原生foreach方法）
     *
     * @param entities List<Region> 实例对象列表
     * @return 影响行数
     * @throws org.springframework.jdbc.BadSqlGrammarException 入参是空List的时候会抛SQL语句错误的异常，请自行校验入参
     */
    int insertOrUpdateBatch(@Param("entities") List<Region> entities);

    @Select("select r2.id as areaId,r2.name as areaName from t_region r1\n" +
            "join t_region r2 on r1.id = r2.pid \n" +
            "join t_cinema c1 on c1.region_id = r2.id\n" +
            "where r1.name = #{locationName} and c1.del_flag = 0\n" +
            "group by region_id")
    List<AreaVO> getAreaByCity(@Param("locationName") String locationName);
}

